package com.compass.doctor.ui.home.view

import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.fragment.app.FragmentActivity
import com.compass.doctor.R
import com.compass.doctor.databinding.ViewInquiryInfoBinding
import com.compass.doctor.ui.WebDetailActivity
import com.compass.doctor.ui.home.InquiryOrderActivity
import com.compass.doctor.ui.home.MedicalCareActivity
import com.compass.doctor.ui.home.PharmacyActivity
import com.compass.doctor.ui.mine.CaSignatureActivity
import com.compass.doctor.ui.prescription.PrescriptionExamineActivity
import com.compass.doctor.ui.prescription.PrescriptionTemplateActivity
import com.compass.framework.constant.TOOLS_URl
import com.compass.framework.ext.gone
import com.compass.framework.ext.onClick
import com.compass.framework.ext.visible
import com.compass.framework.manager.UserInfoManager
import com.compass.framework.model.TodayNumber
import com.compass.framework.toast.TipsToast
import com.compass.framework.utils.getDrawableResource
import com.compass.framework.utils.getStringFromResource

/**
 * Description： 首页问诊信息view
 * Date:2023/12/6 17:38
 */
class InquiryInfoView(activity: FragmentActivity) : LinearLayout(activity) {
    private var binding: ViewInquiryInfoBinding? = null

    init {
        binding =
            ViewInquiryInfoBinding.inflate(LayoutInflater.from(context), this, true)
        initView()

    }

    private fun initView() {


        setLeftView()
        binding?.apply {
            llMyPharmacy.onClick {
                when (UserInfoManager.getUserType()) {
                    "2" -> {
                        //护师
                        MedicalCareActivity.start(context)
                    }

                    "3" -> {

                        if (UserInfoManager.getUserInfo()?.auditPrescriptionAllow==1){
                            //药师
                            if (UserInfoManager.isCASignature()){
                                PrescriptionExamineActivity.start(context)
                            }else{
                                CaSignatureActivity.start(context)
                            }
                        }else{
                            TipsToast.showTips("您没有审方权限")
                        }



                    }
                    else -> {
                        //医生
                        PharmacyActivity.start(context)
                    }

                }


            }
            llPrescriptionTemplate.onClick {

                when (UserInfoManager.getUserType()) {
                    "1" -> {
                        //医生
                        PrescriptionTemplateActivity.start(context, 0)
                    }

                    else -> {
                        //护师,药师

                        WebDetailActivity.start(context, TOOLS_URl,"常用工具")
                    }


                }


            }
            llInquiryTitle.onClick {
                //问诊单
                InquiryOrderActivity.start(context, 0)
            }
            llAwait.onClick {
                //问诊单
                InquiryOrderActivity.start(context, 0)
            }
            llReceived.onClick {
                //问诊单
                InquiryOrderActivity.start(context, 1)
            }
        }
    }

    fun setInquiryInfo(todayNumber: TodayNumber?) {
        todayNumber?.let {
            binding?.tvConsultationNum?.text = it.alreadyReceived.toString()
            binding?.tvFollowersNum?.text = it.patientNum.toString()
            if (UserInfoManager.getUserType()=="3"&&it.pendingReviewNum>0){
                binding?.msgUnread?.visible()
                binding?.msgUnread?.text=it.pendingReviewNum.toString()
            }else{
                binding?.msgUnread?.gone()
            }

        }
    }

    private fun setLeftView() {
        binding?.apply {
            when (UserInfoManager.getUserType()) {
                "1" -> {
                    //医生
                    tvBelowTips.text =
                        getStringFromResource(R.string.home_prescription_template_tip)
                    tvBelowTitle.text = getStringFromResource(R.string.home_prescription_template)
                    imgBelowIcon.background =
                        getDrawableResource(R.mipmap.icon_prescription_template)
                    tvTopTips.text = getStringFromResource(R.string.home_my_pharmacy_tip)
                    tvTopTitle.text = getStringFromResource(R.string.home_my_pharmacy)
                    imgTopIcon.background = getDrawableResource(R.mipmap.icon_my_pharmacy)
                }

                "2" -> {
                    //护师
                    tvTopTips.text = "护理到家服务"
                    tvTopTitle.text = "医护上门"
                    imgTopIcon.background = getDrawableResource(R.mipmap.icon_medical_care)

                    tvBelowTips.text = "医生常用小工具"
                    tvBelowTitle.text = "常用工具"
                    imgBelowIcon.background = getDrawableResource(R.mipmap.icon_tools)
                }

                "3" -> {
                    tvBelowTips.text = "医生常用小工具"
                    tvBelowTitle.text = "常用工具"
                    imgBelowIcon.background = getDrawableResource(R.mipmap.icon_tools)

                    tvTopTips.text = "患者处方审核"
                    tvTopTitle.text = "处方审核"
                    imgTopIcon.background = getDrawableResource(R.mipmap.icon_rx_icon)
                }
            }
        }
    }

}